package cn.hrlly.tao2shou.presenter;

import android.content.Context;

import cn.hrlly.tao2shou.biz.OrderListBiz;
import cn.hrlly.tao2shou.biz.OrderListBizImpl;
import cn.hrlly.tao2shou.domain.OrderList;
import cn.hrlly.tao2shou.listener.OnOrderListListener;
import cn.hrlly.tao2shou.view.view_interface.OrderListView;

/**
 * User: gengliang
 * Date: 2016-01-31
 * Time: 14:39
 */

public class OrderListPresenterImpl implements OrderListPresenter,OnOrderListListener {

    private OrderListBiz orderListBiz;
    private OrderListView orderListView;

    public OrderListPresenterImpl(OrderListView orederListView,Context context) {
        this.orderListView = orederListView;
        this.orderListBiz=new OrderListBizImpl(this,context);
    }

    @Override
    public void showNetOrderList() {
        OrderList orderList=new OrderList();
        orderList.setOrderType(orderListView.getOrderType());
        orderListBiz.getNetOrderList(orderList);
    }

    @Override
    public void showCacheOrderList() {
        int n=orderListView.getOrderType();
        OrderList orderList=new OrderList();
        switch (n){
            case 0:
                orderList=orderListBiz.getCacheBuyerUnfinishOrderList();
                break;
            case 1:
                orderList=orderListBiz.getCacheBuyerCompleteOrderList();
                break;
            case 2:
                orderList=orderListBiz.getCacheSellerUnfinishOrderList();
                break;
            case 3:
                orderList=orderListBiz.getCacheSellerCompleteOrderList();
                break;
        }
        if(orderList!=null)
            orderListView.showListView(orderList);
    }

    @Override
    public void showOrderSucc(OrderList orderList) {
        orderListView.showListView(orderList);

        //将数据缓存
        int n=orderListView.getOrderType();
        switch (n){
            case 0:
                orderListBiz.saveCacheBuyerUnfinishOrderList(orderList);
                break;
            case 1:
                orderListBiz.saveCacheBuyerCompleteOrderList(orderList);
                break;
            case 2:
                orderListBiz.saveCacheSellerUnfinishOrderList(orderList);
                break;
            case 3:
                orderListBiz.saveCacheSellerCompleteOrderList(orderList);
                break;
        }
    }

    @Override
    public void showOrderFail(int errorMessage) {
        orderListView.showMessage(errorMessage);
    }

    @Override
    public void showOrderFail(String errorMessage) {
        orderListView.showMessage(errorMessage);
    }
}
